import toml
from flask import Flask
from flask_cors import CORS
from flask import render_template

def main():
    with open('config.toml', 'r') as f:
        config = toml.load(f)
    app = Flask(__name__)
    CORS(app)

    @app.route('/')
    def welcome():
        return render_template(
            'IndexPage.html',
            front_end_domain_name = config['front_end_domain_name'],
            backend_domain_name = config['backend_domain_name'],
            icon_url = 'https://cloud.baidu.com/img/logo.png'
            )

    @app.route('/index_page', methods = ['GET'])
    def index_page():
        return render_template(
            'IndexPage.html',
            front_end_domain_name = config['front_end_domain_name'],
            backend_domain_name=config['backend_domain_name'],
            icon_url = 'https://cloud.baidu.com/img/logo.png'
            )

    @app.route('/login_register_page', methods = ['GET'])
    def login_register_page():
        return render_template(
            'LoginRegisterPage.htm',
            front_end_domain_name = config['front_end_domain_name'],
            backend_domain_name = config['backend_domain_name'],
            icon_url = 'https://cloud.baidu.com/img/logo.png'
            )
    @app.route('/navigation_page', methods = ['GET'])
    def navigation_page():  
        return render_template(
            'NavigationPage.htm',
            front_end_domain_name = config['front_end_domain_name'],
            backend_domain_name = config['backend_domain_name'],
            icon_url = 'https://cloud.baidu.com/img/logo.png'
            )
    @app.route('/video_processing_page', methods = ['GET'])
    def video_processing_page():  
        return render_template(
            'VideoProcessingPage.htm',
            front_end_domain_name = config['front_end_domain_name'],
            backend_domain_name = config['backend_domain_name'],
            icon_url = 'https://cloud.baidu.com/img/logo.png'
            )
    @app.route('/video_processing_result_page', methods = ['GET'])
    def video_processing_result_page():  
        return render_template(
            'VideoProcessingResultPage.htm',
            front_end_domain_name = config['front_end_domain_name'],
            backend_domain_name = config['backend_domain_name'],
            icon_url = 'https://cloud.baidu.com/img/logo.png'
            )
    @app.route('/show_video_processed_result_page', methods = ['GET'])
    def show_video_processed_result_page():  
        return render_template(
            'ShowVideoProcessedResultPage.htm',
            front_end_domain_name = config['front_end_domain_name'],
            backend_domain_name = config['backend_domain_name'],
            icon_url = 'https://cloud.baidu.com/img/logo.png'
            )
    @app.route('/personal_center_page', methods = ['GET'])
    def personal_center_page():  
        return render_template(
            'PersonalCenterPage.htm',
            front_end_domain_name = config['front_end_domain_name'],
            backend_domain_name = config['backend_domain_name'],
            icon_url = 'https://cloud.baidu.com/img/logo.png'
            )
    @app.route('/ai_chat_page', methods = ['GET'])
    def ai_chat_page():  
        return render_template(
            'AiChatPage.htm',
            front_end_domain_name = config['front_end_domain_name'],
            backend_domain_name = config['backend_domain_name'],
            icon_url = 'https://cloud.baidu.com/img/logo.png'
            )
    @app.route('/image_processing_page', methods = ['GET'])
    def image_processing_page():
        return render_template(
            'ImageProcessingPage.htm',
            front_end_domain_name = config['front_end_domain_name'],
            backend_domain_name = config['backend_domain_name'],
            icon_url = 'https://cloud.baidu.com/img/logo.png'
            )
    @app.route('/pptx_generates_mind_maps_page', methods = ["GET"])
    def pptx_generates_mind_maps():
        return render_template(
            'PptxGeneratesMindMapsPage.htm',
            front_end_domain_name = config['front_end_domain_name'],
            backend_domain_name = config['backend_domain_name'],
            icon_url = 'https://cloud.baidu.com/img/logo.png'
        )
    @app.route('/pptx_generates_questions_page', methods = ["GET"])
    def pptx_generates_questions_page():
        return render_template(
            'PptxGeneratesQuestionsPage.htm',
            front_end_domain_name = config['front_end_domain_name'],
            backend_domain_name = config['backend_domain_name'],
            icon_url = 'https://cloud.baidu.com/img/logo.png'
        )
    @app.route('/pptx_generates_lesson_plans_page', methods = ["GET"])
    def pptx_generates_lesson_plans_page():
        return render_template(
            'PptxGeneratesLessonPlansPage.htm',
            front_end_domain_name = config['front_end_domain_name'],
            backend_domain_name = config['backend_domain_name'],
            icon_url = 'https://cloud.baidu.com/img/logo.png'
        )
    app.run(
        debug = config['debug'], 
        host = config['host'], 
        port = config['port'],
        threaded = True
    )

if __name__ == '__main__':
    main()
